<template>
  <div class="container" ref="mainCon">
    <topTitle :titleText="titleText"></topTitle>
    <div class="mainCon">
      <el-row class="toolbar searchInputWidth" style="padding-bottom: 0">
        <el-form :inline="true" :model="filterField" ref="searchConditions">
          <el-col :lg="8" :xl="6">
            <el-form-item label="区域" class="row-padding-bottom">
              <el-cascader
                ref="manageArea"
                v-model="areaId"
                :options="areasOptions"
                @change="getAreaId"
                clearable
                filterable
                :props="{ checkStrictly: true }"
              ></el-cascader>
            </el-form-item>
          </el-col>
          <el-col :lg="8" :xl="6">
            <el-form-item label="行业" class="row-padding-bottom">
              <el-cascader
                ref="industry"
                v-model="industryId"
                :options="industryOptionsNC"
                @change="getIndustryId"
                clearable
                filterable
                :props="{ checkStrictly: true }"
              ></el-cascader>
            </el-form-item>
          </el-col>
          <template v-if="advanced">
            <el-col :lg="8" :xl="6">
              <el-form-item label="企业" class="row-padding-bottom">
                <el-input
                  v-model="filterField.search"
                  @blur="filterField.search = changeValue($event)"
                  placeholder="企业名称或统一社会信用代码"
                  clearable
                ></el-input>
              </el-form-item>
            </el-col>
            <el-col :lg="8" :xl="6">
              <el-form-item label="工资专户银行" class="row-padding-bottom">
                <el-select
                  v-model="filterField.bankId"
                  clearable
                  filterable
                  placeholder="请选择"
                >
                  <el-option
                    v-for="(item, index) of bankData"
                    :key="index"
                    :label="item.name"
                    :value="item.code"
                  ></el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :lg="8" :xl="6">
              <el-form-item label="专户账号" class="row-padding-bottom">
                <el-input
                  v-model="filterField.bankCardNo"
                  @blur="filterField.bankCardNo = changeValue($event)"
                  placeholder="请输入专户账号"
                  clearable
                ></el-input>
              </el-form-item>
            </el-col>
            <!-- <el-form-item>
                        <el-button type="primary" icon="icon iconfont iconchazhao1" @click="searchList" class="commonBtn"></el-button>
                    </el-form-item> -->
          </template>
          <el-col :lg="8" :xl="6">
            <el-form-item label="">
              <a
                @click="toggleAdvanced"
                style="margin-left: 40px; color: #409eff; cursor: pointer"
                class="btnColor"
              >
                {{ advanced ? '收起' : '展开' }}
                <i
                  :class="advanced ? 'el-icon-arrow-up' : 'el-icon-arrow-down'"
                ></i>
              </a>
              <el-button
                type="primary"
                icon="icon iconfont iconchazhao1"
                @click="searchList"
                class="searchBtn"
              >
                <span>搜索</span>
              </el-button>
            </el-form-item>
            <el-form-item>
              <exportBtn
                :dataLen="tableList.length"
                :filterField="filterField"
                api="api-s/report/export_JC_NC_COMPANY_POXY_PAY_SALARY"
              ></exportBtn>
            </el-form-item>
          </el-col>
        </el-form>
      </el-row>
      <div class="spacing"></div>
      <div
        ref="tableBox"
        :class="hiddleToolBar ? 'tableBoxCur tableBox' : 'tableBoxCur'"
      >
        <el-table
          ref="tableBox1"
          :max-height="tableHeight"
          :data="tableList"
          v-loading="loading"
          :header-cell-style="{ background: '#eef1f6', color: '#606266' }"
          highlight-current-row
          stripe
          style="border: 1px solid #dfe6ec"
        >
          <el-table-column
            prop="areaName"
            label="经营区域"
            :formatter="formatTd"
            min-width="180"
          ></el-table-column>
          <el-table-column
            prop="industryName"
            label="行业"
            :formatter="formatTd"
            min-width="180"
          ></el-table-column>
          <el-table-column prop="companyName,uscc" label="企业" width="230">
            <template slot-scope="scope">
              <copyText
                :tableIndex="scope.$index"
                :copyTextName="scope.row.companyName"
                :columnName="'companyName'"
              ></copyText>
              <p>{{ scope.row.uscc || '--' }}</p>
            </template>
          </el-table-column>
          <el-table-column
            prop="bankName,bankCardNo"
            label="工资专户"
            min-width="130"
          >
            <template slot-scope="scope">
              <p>{{ scope.row.bankName || '' }}</p>
              <p>{{ scope.row.bankCardNo | deseHandler(4, 4, '*') }}</p>
            </template>
          </el-table-column>
          <el-table-column
            prop="shouldPay"
            label="应发总金额（元）"
            :formatter="formatTd"
            min-width="160"
          ></el-table-column>
          <el-table-column
            prop="bankActPay"
            label="实发总金额（元）"
            :formatter="formatTd"
            min-width="160"
          ></el-table-column>
          <el-table-column
            prop="bankActPayCount"
            label="代发总人次"
            :formatter="formatTd"
            min-width="110"
          ></el-table-column>
          <el-table-column label="操作" align="left" fixed="right" width="110">
            <template slot-scope="scope">
              <el-link
                type="primary"
                v-if="isShowDetail"
                @click="enterpriseArchives(scope.row)"
                >查看详情</el-link
              >
              <span v-else>--</span>
            </template>
          </el-table-column>
          <!-- 表格数据为空时，页面显示 -->
          <div slot="empty" v-show="isShow">
            <emptyTable emptyText="暂无相关信息"></emptyTable>
          </div>
        </el-table>
        <!-- filterField为搜索条件 -->
        <!-- getTableList为获取子组件的数据 -->
        <Pagination
          ref="pagination"
          @getpageSize="getpageSize"
          @getpageNo="getpageNo"
          @getList="getTableList"
          :filterField="filterField"
          :requestUrl="requestUrl"
        ></Pagination>
      </div>
    </div>
  </div>
</template>

<script>
import { mapActions, mapState } from 'vuex'
import scrollTable from '@/mixin/scrollTable.js'

export default {
  name: 'salaryDfList',
  mixins: [scrollTable],
  data() {
    return {
      titleText: '企业工资代发',
      advanced: false,
      bankData: [], //银行
      //表格数据
      tableList: [],
      requestUrl: 'api-su/salary/expand/findmonitorsalary',
      areaId: '', //区域
      industryId: '', //行业
      //搜索条件
      filterField: {
        areaId: '', //区域
        industryId: '', //行业
        search: '', //企业
        bankId: '', //专户银行
        bankCardNo: '', //专户账号
      },
      pageSize: 20,
      pageNo: 1,
      companyId: '', //跳转详情传参
      isShow: false, //列表加载
      loading: true,
      isShowDetail: '',
    }
  },
  computed: { ...mapState(['areasOptions', 'industryOptionsNC']) },

  created() {
    this.getBankData()
    //获取行业
    this.getIndustryNC({})
    //获取区域
    this.getAreas({ areaId: this.$store.state.areaInfoArr.areaId })
    this.$nextTick(function () {
      this.$refs.pagination.getTableListData()
    })
    this.isShowDetail =
      this.$store.state.buttonLimitsArr.indexOf('mNcSalaryList:detail') > -1
  },
  activated() {
    this.$nextTick(function () {
      this.$refs.pagination.getTableListData(this.pageNo, this.pageSize)
    })
  },
  methods: {
    toggleAdvanced() {
      this.advanced = !this.advanced
    },
    getpageSize(val) {
      this.pageSize = val
    },
    getpageNo(val) {
      this.pageNo = val
    },
    ...mapActions(['getAreas', 'getIndustryNC']),

    getBankData() {
      var data = {
        type: 'BANK_TYPE',
      }
      this.axios({
        method: 'post',
        url: 'api-bs/base/dicitem/findbytype',
        data: data,
      })
        .then((response) => {
          this.bankData = response.data.result
        })
        .catch((error) => {
          this.$message.error('数据获取失败')
        })
    },
    //获取选中的行业最后一级id
    getIndustryId() {
      var industryId = this.industryId[this.industryId.length - 1]
      this.filterField.industryId = industryId
    },
    //获取选中的区域最后一级id
    getAreaId() {
      var areaId = this.areaId[this.areaId.length - 1]
      this.filterField.areaId = areaId
    },
    getTableList(data) {
      this.tableList = data
      this.loading = false
      if (this.tableList.length < 1) {
        this.isShow = true
      }
    },
    // 搜索
    searchList() {
      this.$refs.pagination.getTableListData()
    },
    //工资代发详情
    enterpriseArchives(row) {
      this.companyId = row.companyId
      this.$router.push({
        path: '/home/businessManagement/enterpriseArchives/',
        name: 'enterpriseArchives',
        query: {
          companyId: this.companyId,
          // qyName: row.companyName,
          // qyUscc: row.uscc,
          name: 'salaryDfList',
        },
      })
      this.$store.commit('CHANGE_SLIDER_NAME', {
        oldUrl: '/home/salaryDf/salaryDfList',
        newUrl: this.$router.currentRoute.fullPath,
      })
    },
  },
}
</script>

<style lang="less" scoped>
.mainCon {
  top: 198px;
  @media screen and (min-width: 1280px) and (max-width: 1366px) {
    .searchInputWidth /deep/.el-form-item__label {
      width: 96px;
    }
  }
}
@import '../../../static/css/filterArea.less';
</style>
